/*
 * @Author: wuheng wuheng@szhbzc.com
 * @Date: 2025-01-04 16:06:59
 * @LastEditors: wuheng wuheng@szhbzc.com
 * @LastEditTime: 2025-02-26 14:19:39
 * @FilePath: \web-appc:\Users\wuheng\Desktop\WugangNew\src\api\upload.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import request from "@/utils/newrequst";
// 获取导入文件数据监听进度
export const GetFileProgressApi = (formData: any, onProgress?: (progress: number) => void) => {
  return request({
    url: `/infra/file/upload`, // 确保 URL 是正确的
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data' // 通常不需要设置这个，因为axios会自动处理
    },
    onUploadProgress: (progressEvent: any) => {
      const percentCompleted = Math.round((progressEvent.loaded * 100) / (progressEvent.total || 1)); // 防止除以0
      if (onProgress) {
        onProgress(percentCompleted);
      }
    }
  });
};
export const GetPricexclFileApi = (formData: any, onProgress?: (progress: number) => void) => {
  return request({
    url: `/purchase/v1/public/sku-supply/import-excel-data-view`, // 确保 URL 是正确的
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data' // 通常不需要设置这个，因为axios会自动处理
    },
    onUploadProgress: (progressEvent: any) => {
      const percentCompleted = Math.round((progressEvent.loaded * 100) / (progressEvent.total || 1)); // 防止除以0
      if (onProgress) {
        onProgress(percentCompleted);
      }
    }
  });
};
// 订货方案导入excel
export const ImportExcelOrderPlanApi = (formData: any, onProgress?: (progress: number) => void) => {
  return request({
    url: `/purchase/v1/public/order-plan-details-temp/import-excel-data-view`, // 确保 URL 是正确的
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data' // 通常不需要设置这个，因为axios会自动处理
    },
    onUploadProgress: (progressEvent: any) => {
      const percentCompleted = Math.round((progressEvent.loaded * 100) / (progressEvent.total || 1)); // 防止除以0
      if (onProgress) {
        onProgress(percentCompleted);
      }
    }
  });
};